package com.lhd.controller;

import com.lhd.pojo.*;
import com.lhd.service.GarbageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/garbage")
public class GarbageController {
    @Autowired
    GarbageService garbageService;
    @GetMapping("/all")
    public Result getAll(){
        List<Garbage> all = garbageService.getAll();
        return Result.success(all);
    }
    @GetMapping("/condition")
    public Result getWithCondition(Garbage garbage, PageCondition pageCondition){
        PageBean<Garbage> pageBean = garbageService.getWithCondition(garbage,pageCondition);
        return Result.success(pageBean);
    }

    @PutMapping
    public Result update(@RequestBody Garbage garbage){
        garbageService.update(garbage);
        return Result.success();
    }
    @PostMapping
    public Result add(@RequestBody  Garbage garbage){
        garbageService.add(garbage);
        return Result.success();
    }
    @DeleteMapping
    public Result remove(Integer id){
        garbageService.remove(id);
        return Result.success();
    }
}
